package rm.ep.shared;

import java.io.Serializable;
import java.util.Random;

import javax.persistence.Id;
import javax.persistence.PrePersist;

import com.googlecode.objectify.annotation.Unindexed;

@SuppressWarnings("serial")
public abstract class AbstractEntity implements Serializable {

	@Id 
	private Long fId;
	
	@Unindexed 
	private Long fCreatedAt = System.currentTimeMillis();
	
	private Long fModifiedAt;
	

	public final Long getId() {
		return fId;
	}
	
	public final Long getCreatedTime() {
		return fCreatedAt;
	}
	
	public final Long getLastModifiedTime() {
		return fModifiedAt;
	}
	
	@Override
	public int hashCode() {
		return 11 * getClass().getName().hashCode() + 23 * fId.hashCode();
	}
	
	@SuppressWarnings("unused")
	@PrePersist
	private void updatedModifiedTime() {
		fModifiedAt = System.currentTimeMillis();
	}
	
	protected static Random RANDOMIZER = new Random();
	
}
